package com.wimcorp.magic.abilities;

import java.rmi.RemoteException;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.wimcorp.magic.abilities.trigger.AbilityTrigger;
import com.wimcorp.magic.cards.Creature;
import com.wimcorp.magic.input.Target;

/**
 * example {target:'OPPONENT',locations:['BATTLEFIELD'],behaviors:}
 * 
 * target options : SELF,OPPONENT,ANY
 * 
 * types options : 'CREATURE'
 * 
 * location options : BATTLEFIELD
 * 
 * behaviors options :
 * 
 * duration :
 */
@Entity
@Table(name = "controlcreature", schema = "abilities")
public class ControlCreature extends Ability {

	@Transient
	private Creature creature = null;

	protected ControlCreature() {
	}

	public ControlCreature(AbilityTrigger trigger) {
		super(trigger);
	}

	public ControlCreature(ControlCreature ability){
		super(ability);
	}
	
	@Override
	protected void executeAbility() {
		creature = (Creature) getAbilityTarget();
		if(creature != null){
			//creature.unsummon();
			//getPlayer().getSummoningPlaines().playCard(creature);
			creature.setPlayer(getPlayer());
			registerUndo();
		}
	}

	public void uncast() {
		if (creature != null) {
			//creature.unsummon();
			//if (creature.isAlive()) {
				creature.setPlayer(getPlayer().getOpponent());
			//}
			//if (creature.isAlive()) {
			//	getPlayer().getOpponent().getSummoningPlaines().playCard(creature);
			//}
		}
	}

	@Override
	public Ability clone() {
		
		return new ControlCreature(this);
	}

	@Override
	public boolean isInputRequired(){
		if (Target.THIS.equals(getTarget())) {
			return false;
		}
		return true;
	}
}
